package com.itc.dispatch.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itc.common.core.domain.R;
import com.itc.common.core.validate.Add;
import com.itc.common.core.validate.Update;
import com.itc.dispatch.domain.dto.AlarmConfigDto;
import com.itc.dispatch.domain.dto.AlarmConfigPageDto;
import com.itc.dispatch.domain.dto.DataSetDto;
import com.itc.dispatch.domain.dto.TriggerDto;
import com.itc.dispatch.domain.vo.AlarmConfigVo;
import com.itc.dispatch.domain.vo.FieldDataVo;
import com.itc.dispatch.service.AlarmConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/alarm/config")
@Api(value = "alarmConfig", tags = "告警配置管理模块")
public class AlarmConfigController {

    @Autowired
    private AlarmConfigService alarmConfigService;

    /**
     * 新增告警管理信息
     * @param
     * @return
     */
    @PostMapping("/add")
    @ApiOperation(value = "新增告警管理信息")
    public R add(@RequestBody @Validated(Add.class) AlarmConfigDto dto){
        return alarmConfigService.add(dto);
    }

    /**
     * 删除告警管理界面信息
     * @param
     * @return
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除告警管理界面信息")
    public R delete(@PathVariable("id") Long id){
        return alarmConfigService.delete(id);
    }

    /**
     * 编辑告警管理信息
     * @param
     * @return
     */

    @PostMapping("/update")
    @ApiOperation(value = "编辑告警管理信息")
    public R updateOne(@RequestBody @Validated(Update.class) AlarmConfigDto dto){
        return alarmConfigService.updateOne(dto);
    }

    /**
     * 获取告警管理界面分页信息
     * @param
     * @return
     */
    @PostMapping("/page")
    @ApiOperation(value = "获取告警管理界面分页信息")
    public R<Page<AlarmConfigVo>> getPage(@RequestBody AlarmConfigPageDto pageDto){
        Page page = new Page();
        page.setCurrent(pageDto.getCurrent());
        page.setSize(pageDto.getSize());
        page.setSearchCount(true);
        return alarmConfigService.getPage(page,pageDto);
    }

    /**
     * 编辑按钮，获取单个告警管理信息
     * @param
     * @return
     */
    @GetMapping("/detail/{id}")
    @ApiOperation(value = "编辑按钮，获取单个告警管理信息")
    public R<AlarmConfigVo> detail(@PathVariable("id") Long id ){
        return alarmConfigService.detail(id);
    }

    /**
     * 关闭/开启告警管理信息
     * @param
     * @return
     */
    @PostMapping("/change/{id}")
    @ApiOperation(value = "关闭/开启告警管理信息")
    public R change(@PathVariable("id") Long id ){
        return alarmConfigService.change(id);
    }

    /**
     * 手动触发告警信息
     * @param
     * @return
     */
    @PostMapping("/trigger")
    @ApiOperation(value = "手动触发告警信息")
    public R trigger(@RequestBody  @Validated TriggerDto dto){
        return alarmConfigService.trigger(dto);
    }

    /**
     * 选择关联预警
     * @param
     * @return
     */
    @GetMapping("/getAlarmData")
    @ApiOperation(value = "选择关联预警")
    public R<List<AlarmConfigDto>> getAlarmData(){
        return alarmConfigService.getAlarmData();
    }




}
